/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nanosl.norg.ent;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Thilina
 */
@Entity
@Table(name = "person_has_person")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PersonHasPerson.findAll", query = "SELECT p FROM PersonHasPerson p"),
    @NamedQuery(name = "PersonHasPerson.findByPersonNIC", query = "SELECT p FROM PersonHasPerson p WHERE p.personHasPersonPK.personNIC = :personNIC"),
    @NamedQuery(name = "PersonHasPerson.findByPersonNIC1", query = "SELECT p FROM PersonHasPerson p WHERE p.personHasPersonPK.personNIC1 = :personNIC1"),
    @NamedQuery(name = "PersonHasPerson.findByRelationshipRelationship", query = "SELECT p FROM PersonHasPerson p WHERE p.personHasPersonPK.relationshipRelationship = :relationshipRelationship")})
public class PersonHasPerson implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PersonHasPersonPK personHasPersonPK;
    @JoinColumn(name = "relationship_relationship", referencedColumnName = "relationship", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Relationship relationship;
    @JoinColumn(name = "person_NIC1", referencedColumnName = "NIC", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Person person;
    @JoinColumn(name = "person_NIC", referencedColumnName = "NIC", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Person person1;

    public PersonHasPerson() {
    }

    public PersonHasPerson(PersonHasPersonPK personHasPersonPK) {
        this.personHasPersonPK = personHasPersonPK;
    }

    public PersonHasPerson(String personNIC, String personNIC1, String relationshipRelationship) {
        this.personHasPersonPK = new PersonHasPersonPK(personNIC, personNIC1, relationshipRelationship);
    }

    public PersonHasPersonPK getPersonHasPersonPK() {
        return personHasPersonPK;
    }

    public void setPersonHasPersonPK(PersonHasPersonPK personHasPersonPK) {
        this.personHasPersonPK = personHasPersonPK;
    }

    public Relationship getRelationship() {
        return relationship;
    }

    public void setRelationship(Relationship relationship) {
        this.relationship = relationship;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Person getPerson1() {
        return person1;
    }

    public void setPerson1(Person person1) {
        this.person1 = person1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (personHasPersonPK != null ? personHasPersonPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PersonHasPerson)) {
            return false;
        }
        PersonHasPerson other = (PersonHasPerson) object;
        if ((this.personHasPersonPK == null && other.personHasPersonPK != null) || (this.personHasPersonPK != null && !this.personHasPersonPK.equals(other.personHasPersonPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.nanosl.norg.ent.PersonHasPerson[ personHasPersonPK=" + personHasPersonPK + " ]";
    }
    
}
